home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / programming / assembly / dskhrdldr.lha / DTrakkerFINAL-Seg.s < prev    next >
Encoding:
Text File  |  1980-01-12  |  5.8 KB  |  352 lines

  1.     Opt    c-
  2. *****************************************************************************
  3. *  Psykos Exteme Hardware Only Disk Routines, Read And Write, Version 8.0   *
  4. *    For in-group use only.    Illeagle wait states at the mo, soon be CIA  *
  5. *  Copyright 1992 The Retro Corporation.                     Psyko 6/11/92  *
  6. *****************************************************************************
  7. ; revitalised 21-5-93 especially 4 nzoid.
  8. ;
  9. ; no hanging up or crashing out, i think.
  10. ;
  11. ; Reg. D0        Reg. D1
  12. ; 0 = SetTrack 0    Drive No.
  13. ;
  14. ; 1 = Start Drive    Drive No.
  15. ;
  16. ; 2 = Read Sector    Sector No.
  17. ; a0 = Data Address    a1 = MFM Buffer
  18. ;
  19. ; 3 = Stop Drive    Drive No.
  20.  
  21.  
  22.  
  23.     Section    "Disk Trakker",Code_C
  24.  
  25. Start          Movem.l    d0-d7/a0-a6,-(sp)
  26.     
  27.     Cmpi.b    #0,d0
  28.     Beq    Set0Ex
  29.     Cmpi.b    #1,d0
  30.     Beq    StartEx
  31.     Cmpi.b    #2,d0
  32.     Beq    ReadEx
  33.     Cmpi.b    #3,d0
  34.     Beq    StopEx
  35.     
  36. ReadEx    Lea    StartSector(pc),a6
  37.     Move.w    d1,(a6)
  38.     Lea    MFMBufferPt(pc),a6
  39.     Move.l    a1,0(a6)
  40.     Move.l    a0,4(a6)
  41.     Bsr    Initialize
  42.     Lea    Drive(pc),a0
  43.     Moveq    #0,d1
  44.     Move.w    (a0),d1
  45.     Add.w    d1,d1
  46.     Lea    DTrack0(pc),a0
  47.     Move.w    (a0,d1),8(a0)
  48.     Bsr    LoadSector
  49.     Lea    Drive(pc),a0
  50.     Moveq    #0,d1
  51.     Move.w    (a0),d1
  52.     Add.w    d1,d1
  53.     Lea    DTrack0(pc),a0
  54.     Move.w    8(a0),(a0,d1)    
  55. Quit    Bsr    RestoreSystem
  56. QuitEx    Movem.l    (sp)+,d0-d7/a0-a6
  57.     Moveq    #0,d0
  58.     Rts
  59.     
  60. Set0Ex    Lea    Drive(pc),a0
  61.     Move.w    d1,(a0)
  62.     Add.w    d1,d1
  63.     Lea    DTrack0(pc),a0
  64.     Move.w    #0,(a0,d1)
  65.     Bsr    StartDrive
  66.     Bsr    GotoTrack0
  67.     Bra    QuitEx
  68.     
  69. StartEx    Lea    Drive(pc),a0
  70.     Move.w    d1,(a0)
  71.     Bsr    StartDrive
  72.     Bra    QuitEx
  73.  
  74. StopEx    Lea    Drive(pc),a0
  75.     Move.w    d1,(a0)
  76.     Bsr    StopDrive
  77.     Bra    QuitEx
  78.  
  79. Initialize    Lea    $Dff000,a6
  80.     Lea    AdkSav(pc),a0
  81.     Move.w    $10(a6),d0
  82.     Move.w    d0,(a0)
  83.     Move.w    #$7fff,$9e(a6)
  84.     Move.w    #$8100,$9e(a6)
  85.     Rts
  86.  
  87.  
  88. StartDrive    Move.w    Drive(pc),d1
  89.     And.w    #3,d1
  90.     Add.b    #3,d1
  91.     Bclr    #7,$Bfd100
  92.     Nop
  93.     Nop
  94.     Nop
  95.     Bclr    d1,$Bfd100
  96.     Bsr    WaitDrive
  97.         Rts
  98.  
  99. StopDrive    Move.w    Drive(pc),d1
  100.     And.w    #3,d1
  101.     Add.b    #3,d1
  102.     Bset    #7,$Bfd100
  103.     Nop
  104.     Nop
  105.     Nop
  106.     Bclr    d1,$Bfd100
  107.     Nop
  108.     Nop
  109.     Nop
  110.     Bset    d1,$Bfd100
  111.     Bsr    WaitDrive
  112.         Rts
  113.  
  114. MFMAmount    = $3400
  115.  
  116. ReadMFM    Move.l    MFMBufferPt(pc),a0
  117.     Move.w    #MFMAmount,d7
  118. ClearMFMBuffer    Move.b    #$0,(a0)+
  119.     Dbf    d7,ClearMFMBuffer
  120.     
  121.     Bsr    SetDiskSide
  122.     Lea    $Dff000,a6
  123.     Move.w    #$8210,$96(a6)
  124.     Move.w    #2,$9c(a6)
  125.     Move.w    ReadSync(pc),$7e(a6)
  126.     Move.l    MFMBufferPt(pc),$20(a6)
  127.     Move.w    #$7f00,$9e(a6)
  128.     Move.w    #$4000,$24(a6)
  129.     Move.w    #$9500,$9e(a6)
  130.     Bsr    WaitDrive
  131.     Move.w    #(MFMAmount/2)!$8000,d1
  132.     Move.w    d1,$24(a6)
  133.     Move.w    d1,$24(a6)
  134.     Bsr    WaitDiskDMA
  135.     Move.w    #$0010,$96(a6)
  136.     Rts    
  137.  
  138. WaitDrive    Move.l    d6,-(sp)
  139.     Move.w    #20,d6
  140. WaitX    Move.w    #20,d0
  141.     Bsr    WaitRaster
  142.     Btst    #5,$Bfe001
  143.     Beq    NoWaitX
  144.     Dbf    d6,WaitX
  145. NoWaitX    Move.l    (sp)+,d6
  146.     Rts
  147.  
  148. WaitDiskDMA    Move.w    $1e(a6),d0
  149.     Btst    #1,d0
  150.     Beq    WaitDiskDMA
  151.     Move.w    #2,$9c(a6)
  152.     Rts
  153.  
  154. WaitRaster    Move.b    $Dff006,d7
  155. WaitNextLine    Cmp.b    $Dff006,d7
  156.     Beq    WaitNextLine
  157.     Dbf    d0,WaitRaster
  158.     Rts
  159.  
  160. DecodeMFM    Move.l    MFMBufferPt(pc),a2
  161.     Lea    MFMSectorList(pc),a5
  162.     Moveq.l    #10,d5
  163. DecodeLoop    Move.l    #$55555555,d7
  164. FindSync1    Move.w    ReadSync(pc),d3
  165.     Move.w    (a2)+,d4
  166.     Cmp.w    d3,d4
  167.     Bne    FindSync1
  168.     Move.w    (a2),d4
  169.     Cmp.w    d3,d4
  170.     Bne    NoSync
  171.     Addq.l    #2,a2
  172. NoSync    Move.l    (a2),d3
  173.     Move.w    6(a2),d4
  174.     And.w    d7,d3
  175.     And.w    d7,d4
  176.     Add.w    d3,d3
  177.     Or.w    d4,d3
  178.     Add.w    d3,d3
  179.     Moveq    #0,d6
  180.     And.w    #$ff00,d3
  181.     Asr.w    #7,d3
  182.     Move.w    d3,d6
  183.     Lea    $38(a2),a2
  184.     Move.l    a2,(a5,d6)
  185.     Lea    $200(a2),a2
  186.     Dbf    d5,DecodeLoop
  187.     Rts
  188.  
  189. DecodeSectors    Lea    DataBufferPt(pc),a4
  190.     Move.l    (a4),a3
  191.     Lea    MFMSectorList(pc),a0
  192.     Moveq    #10,d5    
  193.     Move.w    SectorLoad(pc),d0
  194. GetSector    Move.l    (a0)+,a2
  195.     Btst    #0,d0
  196.     Bne    DecSector
  197.     Asr.w    #1,d0
  198.     Dbf    d5,GetSector
  199.     Rts
  200.     
  201. DecSector    Moveq.l    #$7f,d6
  202.     Move.l    #$55555555,d7
  203. DecodeSector    Move.l    $200(a2),d3
  204.     Move.l    (a2)+,d4
  205.     And.l    d7,d4
  206.     And.l    d7,d3
  207.     Add.l    d4,d4
  208.     Or.l    d3,d4
  209.     Move.l    d4,(a3)+
  210.     Dbf    d6,DecodeSector
  211.     Asr.w    #1,d0
  212.     Dbf    d5,GetSector
  213.     Move.l    a3,(a4)
  214.     Rts
  215.  
  216. GotoTrack0      Btst    #4,$Bfe001
  217.             Beq    FoundTrack0
  218.             Bset    #1,$Bfd100
  219.             Bclr    #0,$Bfd100
  220.             Bset    #0,$Bfd100
  221.             Bsr    WaitDrive
  222.             Bra    GotoTrack0
  223. FoundTrack0        Bsr    WaitDrive
  224.             Rts
  225.  
  226. IncTrack    Bclr    #1,$Bfd100
  227.     Move.w    #1,d0
  228.     Bsr    WaitRaster
  229.             Bclr    #0,$Bfd100
  230.     Move.w    #1,d0
  231.     Bsr    WaitRaster
  232.             Bset    #0,$Bfd100
  233.             Bsr    WaitDrive
  234.     Rts
  235.  
  236. DecTrack    Bset    #1,$Bfd100
  237.     Move.w    #1,d0
  238.     Bsr    WaitRaster
  239.             Bclr    #0,$Bfd100
  240.     Move.w    #1,d0
  241.     Bsr    WaitRaster
  242.             Bset    #0,$Bfd100
  243.             Bsr    WaitDrive
  244.     Rts
  245.  
  246. SetDiskSide    Move.w    DiskSide(pc),d4
  247.     Btst    #0,d4
  248.     Bne    SetSide1
  249.     Bset    #2,$Bfd100
  250.     Bra    SideSet
  251. SetSide1    Bclr    #2,$Bfd100
  252. SideSet    Rts
  253.  
  254. RestoreSystem    Lea    $Dff000,a6
  255.     Move.w    ADKsav(pc),d0
  256.             Bset    #15,d0
  257.             Move.w    d0,$9e(a6)
  258.             Rts
  259.  
  260. FindTrack    Bsr    WaitDrive
  261.     Move.w    Track(pc),d0
  262.     Move.w    LTrack(pc),d1
  263.     Cmp.b    d1,d0
  264.     Beq    GotTrack
  265.     Cmp.b    d1,d0
  266.     Bls    AddTrack
  267.     Cmp.b    d1,d0
  268.     Bgt    SubTrack
  269.     Bra    FindTrack
  270. AddTrack    Movem.l    d0-d7/a0-a6,-(sp)
  271.     Lea    Track(pc),a0
  272.     Add.w    #1,(a0)
  273.     Bsr    IncTrack
  274.     Movem.l    (sp)+,d0-d7/a0-a6
  275.     Bra    FindTrack
  276. SubTrack    Movem.l    d0-d7/a0-a6,-(sp)
  277.     Lea    Track(pc),a0
  278.     Sub.w    #1,(a0)
  279.     Bsr    DecTrack
  280.     Movem.l    (sp)+,d0-d7/a0-a6
  281.     Bra    FindTrack
  282. GotTrack    Rts    
  283.  
  284. LoadSector    Lea    SectorsLoaded(pc),a0
  285.     Move.w    StartSector(pc),d0
  286.     Moveq    #0,d7
  287. CheckLoop    Move.w    (a0)+,d1
  288.     Cmp.w    d0,d1
  289.     Beq    FoundSecLoad
  290.     Addq    #1,d7
  291.     Cmpi.b    #11,d7
  292.     Bne    CheckLoop
  293.     Bra    LoadNewMFM
  294.     
  295. FoundSecLoad    Moveq    #0,d6
  296.     Bset    d7,d6
  297.     Lea    SectorLoad(pc),a5
  298.     Move.w    d6,(a5)
  299.     Bsr    DecodeSectors
  300.     Rts
  301.     
  302. LoadNewMFM    Move.w    StartSector(pc),d0
  303.     Lea    DiskSide(pc),a5
  304.     Divs    #11,d0
  305.     Move.l    d0,d1
  306.     Move.w    d0,0(a5)
  307.     Asr.w    #1,d0
  308.     Move.w    d0,4(a5)
  309.     Swap    d1
  310.     Moveq    #0,d6
  311.     And.w    #$f,d1
  312.     Bset    d1,d6
  313.     Move.w    d6,6(a5)
  314.     Bsr    FindTrack
  315.     Bsr    ReadMFM
  316.     Bsr    DecodeMFM
  317.     Bsr    DecodeSectors
  318.     Move.w    DiskSide(pc),d0
  319.     Muls    #11,d0
  320.     Lea    SectorsLoaded(pc),a0
  321.     Moveq    #10,d7
  322. SaveSecLoad    Move.w    d0,(a0)+
  323.     Addq    #1,d0
  324.     Dbf    d7,SaveSecLoad
  325.     Rts
  326.  
  327. StartSector    Dc.w    880
  328.  
  329. MFMBufferPt     Dc.l    $b0000
  330. DataBufferPt    Dc.l    $c0000
  331. ADKsav      Dc.w    0
  332.  
  333. ReadSync    Dc.w    $4489
  334.  
  335. DTrack0    Dc.w    0
  336. DTrack1    Dc.w    0
  337. DTrack2    Dc.w    0
  338. DTrack3    Dc.w    0
  339. Track    Dc.w    0
  340. DiskSide    Dc.w    0
  341. Drive    Dc.w    0
  342. LTrack    Dc.w    40
  343. SectorLoad    Dc.w    0
  344.  
  345. MFMSectorList    Ds.l    11
  346.  
  347. SectorsLoaded    Dcb.w    11,$ffff
  348.  
  349.  
  350.  
  351.  
  352.